﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Dtos;
using IBLL;
using IDAL;
using Model;

namespace BLL
{
    public class FinishWorkBll:IFinishWorkBll
    {
        private IFinishWorkDal _F;
        public FinishWorkBll(IFinishWorkDal F) 
        {
            _F = F;
        }
        public async Task<int> AddFinisWorkAsync(Guid id, Guid id2, int a) 
        {
            return await _F.AddAsync(new Model.FinishWork
            {
                homeworkId = id,
                studentId = id2,
                workStatus = a
            });
        
        }
        public async Task<int> EditFinisWorkAsync(Guid id, Guid homeworkId, Guid studentId, int workStatus)
        {
            var data = await _F.GetIdAll(id);
            if (data == null)
                return 0;
            data.homeworkId = homeworkId;
            data.studentId = studentId;
            data.workStatus = workStatus;
            data.UpdateTime = DateTime.Now;
            return await _F.UpdateAsync(data);
        }

        public async Task<List<FinishWorkDtos>> getAllFinisWork()
        {
            var data = await _F.GetAll();
            return data.Select(d => new FinishWorkDtos
            {
                Id = d.Id,
                HomeworkId = d.homeworkId,
                studentId = d.studentId,
                UpdateTime = DateTime.Now
            }).OrderByDescending(d => d.UpdateTime).ToList();
        }

        Task<int> IFinishWorkBll.DeleteFinisWorkAsync(Guid id)
        {
            throw new NotImplementedException();
        }

        Task<FinishWorkDtos> IFinishWorkBll.GetFinisWorkIdAsync(Guid id)
        {
            throw new NotImplementedException();
        }
    }
}
